package com.tarena.lbs.basic.web.controller;

import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.web.service.AreaService;
import com.tarena.lbs.common.basic.converter.AreaConverter;
import com.tarena.lbs.pojo.basic.bo.AreaBO;
import com.tarena.lbs.pojo.basic.vo.AreaVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
public class AreaController {
    @Autowired
    private AreaService areaService;
    @Autowired
    private AreaConverter areaConverter;

    //地理位置(子查询)
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> proviceList() throws BusinessException{
        List<AreaBO> bos = areaService.queryAreaList(0L);
        List<AreaVO> areaVOS = areaConverter.boList2VoList(bos);
        return new Result<>(areaVOS);
    }

    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> childrenList(@PathVariable Long parentId)throws BusinessException {
        log.debug("区域子查询接口的入参 parentId:{}L",parentId);
        List<AreaBO> bos = areaService.queryAreaList(parentId);
        List<AreaVO> areaVOS = areaConverter.boList2VoList(bos);
        return new Result<>(areaVOS);
    }
}
